package beyjava.model;

import java.util.Date;
import java.util.Vector;


/**
 * @author BEYJAVA
 * model class Activity
 */
public class Activity {
 private Integer actNumber;
 private String actDesc;
 private Date actStartDate;
 private String actDeliver;
 private Integer hours;
 private Project activityProject;
 private Vector<Task> activityTasks;
 /**
 * constructor of activity class
 * @param actNumber
 * @param actDesc
 * @param actStartDate
 * @param actDeliver
 * @param hours
 * @param actProject
 */
public Activity(Integer actNumber, String actDesc, Date actStartDate,
			String actDeliver,Integer hours , Project actProject) {
		super();
		this.actNumber = actNumber;
		this.actDesc = actDesc;
		this.actStartDate = actStartDate;
		this.actDeliver = actDeliver;
		this.hours = hours;
		this.activityProject = actProject;
		this.activityTasks  = new Vector<Task>();
	}
 /**
 * @param actNumber
 * @param actDesc
 * @param actStartDate
 * @param actDeliver
 * @param actHours
 * @param activityProject
 * @return Activity control to check whether activity is null or created
 */
public static Activity createActivity(Integer actNumber, String actDesc, Date actStartDate,String actDeliver, Integer actHours,
		Project activityProject){
		Activity act = null;
		if(activityProject != null){
			act = new Activity(actNumber , actDesc ,actStartDate ,actDeliver ,actHours ,activityProject);
	        activityProject.addActivityToProject(act);	
		}
		return act;
	}
/**
 * @param task
 * @return success check whether the task is added successfully or not.
 */
public boolean addTaskToActivity(Task task){
			 boolean success = false;
			 success = this.getActivityTasks().add(task);
			 this.setHours(this.getHours() + task.getTaskHours());
			 return success;
}
 /**
 * @param task
 * @return success check whether the task is removed successfully or not
 */
public boolean removeTaskFromActivity(Task task){
	 boolean success = false;
	 success = this.getActivityTasks().remove(task);
	 this.setHours(this.getHours()-task.getTaskHours());
	 return success;
 }
/**
 * @param actNumber
 */
public void setActNumber(Integer actNumber) {
	this.actNumber = actNumber;
}
/**
 * @return actNumber
 */
public Integer getActNumber() {
	return actNumber;
}
/**
 * @param actDesc
 */
public void setActDesc(String actDesc) {
	this.actDesc = actDesc;
}
/**
 * @return actDes
 */
public String getActDesc() {
	return actDesc;
}
/**
 * @param actStartDate
 */
public void setActStartDate(Date actStartDate) {
	this.actStartDate = actStartDate;
}
/**
 * @return actStartDate
 */
public Date getActStartDate() {
	return actStartDate;
}
/**
 * @param actDeliver
 */
public void setActDeliver(String actDeliver) {
	this.actDeliver = actDeliver;
}
/**
 * @return actDeliver
 */
public String getActDeliver() {
	return actDeliver;
}
/**
 * @param hours
 */
public void setHours(Integer hours) {
	this.hours = hours;
}
/**
 * @return hours
 */
public Integer getHours() {
	return hours;
}
/**
 * @param activityProject
 */
public void setActivityProject(Project activityProject) {
	this.activityProject = activityProject;
}
/**
 * @return activityProject
 */
public Project getActivityProject() {
	return activityProject;
}
/**
 * @param newActivitytTasks
 */
public void setActivityTasks(Vector<Task> newActivitytTasks) {
	this.activityTasks = newActivitytTasks;
}
/**
 * @return activityTasks
 */
public Vector<Task> getActivityTasks() {
	return activityTasks;
}
 /**
 * @param newAct
 * @return true if update activity is done correctly
 */
public boolean updadateActiviyOfProject(Activity newAct){
	if(newAct != null){
	   this.setActDeliver(newAct.getActDeliver());
	   this.setActDesc(newAct.getActDesc());
	   this.setActStartDate(newAct.getActStartDate());
	   this.setHours(newAct.getHours());
	   return true;
    }
   return false;
  }
@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
			+ ((actDeliver == null) ? 0 : actDeliver.hashCode());
	result = prime * result + ((actDesc == null) ? 0 : actDesc.hashCode());
	result = prime * result + ((actNumber == null) ? 0 : actNumber.hashCode());
	result = prime * result
			+ ((actStartDate == null) ? 0 : actStartDate.hashCode());
	result = prime * result
			+ ((activityProject == null) ? 0 : activityProject.hashCode());
	result = prime * result
			+ ((activityTasks == null) ? 0 : activityTasks.hashCode());
	result = prime * result + ((hours == null) ? 0 : hours.hashCode());
	return result;
}
@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	Activity other = (Activity) obj;
	if (actDeliver == null) {
		if (other.actDeliver != null)
			return false;
	} else if (!actDeliver.equals(other.actDeliver))
		return false;
	if (actDesc == null) {
		if (other.actDesc != null)
			return false;
	} else if (!actDesc.equals(other.actDesc))
		return false;
	if (actNumber == null) {
		if (other.actNumber != null)
			return false;
	} else if (!actNumber.equals(other.actNumber))
		return false;
	if (actStartDate == null) {
		if (other.actStartDate != null)
			return false;
	} else if (!actStartDate.equals(other.actStartDate))
		return false;
	if (activityProject == null) {
		if (other.activityProject != null)
			return false;
	} else if (!activityProject.equals(other.activityProject))
		return false;
	if (activityTasks == null) {
		if (other.activityTasks != null)
			return false;
	} else if (!activityTasks.equals(other.activityTasks))
		return false;
	if (hours == null) {
		if (other.hours != null)
			return false;
	} else if (!hours.equals(other.hours))
		return false;
	return true;
}
@Override
public String toString() {
	return "Activity [actNumber=" + actNumber + ", actDesc=" + actDesc
			+ ", actStartDate=" + actStartDate + ", actDeliver=" + actDeliver
			+ ", hours=" + hours + ", activityProject=" + activityProject
			+ ", activityTasks=" + activityTasks + "]";
}

}
